/*
 * FileName: ReentrantLockCondition.java
 * Author:   zzw
 * Date:     2018年05月14日
 * Description:
 */
package com.zzw.thread;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 〈〉<br>
 * 〈〉
 *
 * @author zzw
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本]（可选）
 */
public class ReentrantLockCondition implements Runnable{

    private static ReentrantLock lock = new ReentrantLock();
    private static Condition condition = lock.newCondition();

    @Override
    public void run() {
        lock.lock();
        try {
            System.out.println("wait ...");
            condition.await();
            System.out.println("Thread is going on");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ReentrantLockCondition reentrantLockCondition = new ReentrantLockCondition();
        new Thread(reentrantLockCondition).start();
        Thread.sleep(2000);
        System.out.println("get lock");
        lock.lock();
        condition.signal();
        lock.unlock();
    }
}
